#ifndef PFS_BLOCK_LOCATE_H
#define PFS_BLOCK_LOCATE_H

#include <vector>
#include "define.h"
#include <stdint.h>
#include <algorithm>
#include <time.h>

using namespace std;

namespace PFS
{
    class BlockLocate
    {
        public:
            BlockLocate()
                :master_data_server(0),last_leave_time(0),last_join_time(0)
            { }
            virtual ~BlockLocate()
            {
                if(!data_server_list.empty())
                    data_server_list.clear();
            }
            inline const BlockInfo* get_block_info() const
            { return &block_info; }
            inline BlockInfo* get_block_info()
            {
                return &block_info;
            }

            void set_block_info(const BlockInfo& info)
            {
                block_info = info;
            }
            inline const vector<uint64_t>* get_data_server() const
            { return &data_server_list; }
            inline vector<uint64_t>* get_data_server()
            {
                return &data_server_list;
            }
            inline uint64_t get_master_data_server() const
            { return master_data_server; }
            void set_master_data_server(const uint64_t id);

            bool leave(const uint64_t id);

            bool join(const uint64_t id, bool before = false);

            inline time_t get_last_join_time() const
            {
                return last_join_time;
            }

            inline time_t get_last_leave_time() const
            {
                return last_leave_time;
            }
        private:
            BlockInfo block_info;
            vector<uint64_t> data_server_list;
            uint64_t master_data_server;
            time_t last_leave_time;
            time_t last_join_time;
    };
}

#endif
